package shop;

import java.util.ArrayList;

public class Mart{
	
static private ArrayList<Goods> List = new ArrayList<Goods>();
	
	public void addGoods(String name,double price) {
		Goods goods = new Goods(name,price);
		List.add(goods);
	}
	
	public void Show(){
		System.out.println("商品列表:");
		for (int i = 0; i < List.size(); i++) {
			System.out.println("商品序号： "+ i + " " + List.get(i).toString());
		}
	}
	
	public void search(String name) {
		boolean f = false;
		System.out.println("搜索结果:");
		for (int i = 0; i < List.size(); i++) {
			if(name.equals(List.get(i).getName())) {
				System.out.println("商品序号： "+ i + " " + List.get(i).toString());
				f = true ;
				break;
			}
		}
		if(!f) System.out.println("Not Found!");
	}
	
        public int searchToGui(String name){
            
		for (int i = 0; i < List.size(); i++) {
			if(name.equals(List.get(i).getName())) {
				return i;
			}
		}
		return -1;
        }
        
	public Goods getOne(int i) {
		//System.out.println(List.get(i).getName());
		return List.get(i);
	}

	public static String show() {
		// TODO Auto-generated method stub
		String str = "";
		boolean f = false;
		for (int i = 0; i < List.size(); i++) {
			if(!f) str = str  + "商品序号： "+ i + " " + List.get(i).toString();
			else str = str + "<br>" + "商品序号： "+ i + " " + List.get(i).toString();
			f = true;
		}
		return "<html><body>"+str+"</body></html>";
	}

}
